package actions;

import game.constants.ReferenceAction;
import interfaces.ActionInterface;
import interfaces.impl.Action;
import objects.WorldObject;
import universe.Universe;
import constants.Constants;
import extra.Position;

public class ActionDropObject extends Action{
	
	WorldObject objectToDrop=null;
	private int owner=Constants.NO_OWNER;

	@Override
	public boolean processActionChild(Universe universe) {
		System.out.println("dejo caer el objeto");
		if(objectToDrop==null){
			return false;
		}
		System.out.println("dejo caer el objeto1");
		if(!target.containsObject(objectToDrop)){
			return false;
		}
		System.out.println("dejo caer el objeto2");
		WorldObject obj = target.getObject(objectToDrop.getID());
		if(obj==null){
			return false;
		}
		System.out.println("dejo caer el objeto3");
		if(!target.getListObjects().remove(obj)){
			return false;
		}
		
		double x=target.getPosition().getX()+target.getImageObject().getImageToShow().getWidth();
		double y=target.getPosition().getY();
		
		obj.setPosition(new Position(x,y));
		//obj.setOwner(Constants.NO_OWNER);
		obj.setOwner(owner);
		universe.addObject(obj);
		
		
		return true;
	}

	@Override
	public void initializeName() {
		name="Action Drop Object";
		
	}

	@Override
	public void initializeId() {
		this.id=ReferenceAction.ACTION_DROP_OBJECT;
		
	}

	@Override
	public void modifyChild(ActionInterface action) {
		if( action instanceof ActionDropObject){
			objectToDrop=((ActionDropObject) action).objectToDrop;
			owner = ((ActionDropObject) action).owner;
		}
		
	}
	
	@Override
	public ActionDropObject cloneAction(){
		ActionDropObject action = new ActionDropObject();
		action.modifyAction(this);
		return action;
		
	}

	public WorldObject getObjectToDrop() {
		return objectToDrop;
	}

	public void setObjectToDrop(WorldObject objectToDrop) {
		this.objectToDrop = objectToDrop;
	}

	public int getOwner() {
		return owner;
	}

	public void setOwner(int owner) {
		this.owner = owner;
	}

	
	
}
